package com.twu.biblioteca;

import java.util.ArrayList;

/**
 * Created by renatagrfarias on 10/1/14.
 */
public class MovieRepository {

    private ArrayList<Movie> movies = new ArrayList();

    public void createMovies(){
        createMovies("0","Kill Bill: Vol. 1", "Quentin Tarantino", "2003", 10);
        createMovies("1", "Death Proof", "Quentin Tarantino", "2007", 9);
        createMovies("2", "The Godfather", "Francis Ford Coppola", "1972", 10);
        createMovies("3", "Taxi Driver", "Martin Scorsese", "1976", 9);
    }

    public void createMovies(String id, String name, String director, String year, int rating) {
        Movie movie = new Movie(id, name, director, year, rating);
        movies.add(movie);
    }

    public void listMovies(){
        System.out.println("--------------------- List of movies -------------------");
        for(int i=0;i<movies.size();i++) {
            if (!movies.get(i).getCheckOut()) {
                System.out.println(movies.get(i).getId() + " " + movies.get(i).getName() + " - " + movies.get(i).getDirector() + ", " + movies.get(i).getYear() + " Rating: " + movies.get(i).getRating());
            }
        }
        System.out.println("--------------------------------------------------------");
    }

    public Movie searchMovie(String id){
        Movie movie = null;
        for(int i=0;i<movies.size();i++){
            if(movies.get(i).getId().equals(id)){
                movie = movies.get(i);
            }
        }
        return movie;
    }

    public void checkOutMovie(Movie movie){
        movie.setCheckOut(true);
    }

    public boolean movieAvailability(Movie movie){
        if(movie != null) {
            if (movie.getCheckOut()) {
                return false;
            }
            return true;
        }else
            return false;
    }

}
